package com.itheima.springrabbitmqconsumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQListener implements ChannelAwareMessageListener {
    @Override
    @RabbitListener(queues = "boot_queue")
    public void onMessage(Message message, Channel channel) throws Exception {
        long contentLength = message.getMessageProperties().getContentLength();
        System.out.println(new String(message.getBody()));
        channel.basicNack(contentLength,true,false);
    }
}
